package util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendMsgUtil {
    // 发送短信的方法
    public static void sendMsg(String phone, String msgCode) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao", "LTAI4GK43f1hR5Fx7dgkGgGM", "uAKW9CbTFrCqktR81dwlktpjInjFy2");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "仿小米");
        request.putQueryParameter("TemplateCode", "SMS_200193258");
        request.putQueryParameter("TemplateParam", "{\"code\":\"" + msgCode + "\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);

            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SendMsgUtil.sendMsg("18105312625","2345");
    }
}